package com.example.springboot.controller;

import com.example.springboot.common.Result;
import com.example.springboot.controller.dto.LoginDTO;
import com.example.springboot.controller.request.CollectionsPageRequest;
import com.example.springboot.controller.request.LoginRequest;
import com.example.springboot.entity.Collections;
import com.example.springboot.service.ICollectionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin  //解决跨域错误
@RestController
@RequestMapping("/collections")
//是rest风格的collectionscontroller
public class CollectionsController {

    @Autowired
    ICollectionsService collectionsService;


    //    CollectionsPageRequest传入用户名和电话信息
    @GetMapping("/page")
    public Result page(CollectionsPageRequest collectionsPageRequest){
        //        返回数据 Result.success传入一个对象
        return Result.success(collectionsService.page(collectionsPageRequest));

    }

//    post put get delete对应增改查删四类操作
    //    新增会员
    @PostMapping("/save")
    public Result save(@RequestBody Collections collections){
        collectionsService.save(collections);
        return Result.success();
    }

//    更新会员信息
    @PutMapping("/update")
    public Result update(@RequestBody Collections collections){
        collectionsService.update(collections);
        return Result.success();
    }

    //    获取用户列表
    @GetMapping("/list")
    public Result list(){
        //        返回数据
        List<Collections> collectionss=collectionsService.list();
//        System.out.println("collectionss内容是"+collectionss);
        return Result.success(collectionss);

    }


//    根据ID更新用户信息
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Collections collections =collectionsService.getById(id);
        return Result.success(collections);

    }

    //删除操作:
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        collectionsService.deleteById(id);
        return Result.success();
    }



    /*
    最初是通过List返回所有数据,而建立Result后采用Result返回数据
    @GetMapping("/list")
    public List<Collections> listCollectionss(){
        return collectionsService.listCollectionss();
    }
     */
}
